#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

//mknod /dev/com0 c 101 0
//mknod /dev/com1 c 101 1

int main(int argc, char **argv)
{
	int fd0 = 0;
	int fd1 = 0;
	int len = 0;
	int minor = 0;

	//open fd0
	fd0 = open("/dev/com0", O_RDWR);
	if(fd0 < 0) {
		perror("open /dev/com0 fail \n");
		return 0;
	} else {
		printf("open /dev/com0 success \n");
	}

	//read fd0
	len = read(fd0, &minor, sizeof(minor));
	printf("read /dev/com0: %d, size: %d \n", minor, len);
	close(fd0);

	//open fd1
	fd1 = open("/dev/com1", O_RDWR);
	if(fd1 < 0) {
		perror("open /dev/com1 fail \n");
		return 0;
	} else {
		printf("open /dev/com0 success \n");
	}

	//read fd2
	len = read(fd1, &minor, sizeof(minor));
	printf("read /dev/com1: %d, size: %d \n", minor, len);
	close(fd1);

	return 0;
}
